import { isAndroid, isIOS } from '@/utils/navigator'
// 下载app
export const download_app = () => {
  if (isIOS) {
    window.open('https://itunes.apple.com/app/id6475151245')
    setTimeout(() => {
      window.location.href = 'https://itunes.apple.com/app/id6475151245'
    })
  } else if (isAndroid) {
    window.open('https://play.google.com/store/apps/details?id=com.sya.aichat')
  }
}

// 打开指定的app bot聊天页面
// 如果打不开就直接跳转到app下载页
// 需要传入一个aiId
export const open_bot_app = (aiid: number) => {
  location.href = `syachat://chat?uid=${aiid}`
  const checkOpen = setTimeout(() => {
    clearTimeout(checkOpen)
    download_app()
  }, 3000)

  document.addEventListener('visibilitychange', () => {
    const isHidden = document.hidden
    if (isHidden) {
      clearTimeout(checkOpen)
    }
  })
}
